<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="com.engine.salary.encrypt.AESEncryptUtil" %>
<%@ page import="weaver.common.DateUtil" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Date" %>
<%--测试接口--%>
<%
    JSONObject resultJson = new JSONObject();
    BaseBean baseBean = new BaseBean();
    String id = Util.null2String(request.getParameter("id"));
    String items = Util.null2String(request.getParameter("items"));
    baseBean.writeLog(">>>>>>computeSalary_Ajax.jsp>>>>>id=" + id);
    try {
        if (!"".equals(items)) {
            baseBean.writeLog(">>>>>>computeSalary_Ajax.jsp>>>>>执行开始");
            JSONObject columnJson = getLockColumns(id);
            baseBean.writeLog(">>>>>>computeSalary_Ajax.jsp>>>>>columnJson=" + columnJson);
            JSONObject paramJson = JSONObject.parseObject(items);
            baseBean.writeLog(">>>>>>computeSalary_Ajax.jsp>>>>>paramJson=" + paramJson);
            String resourceid = Util.null2String(paramJson.getString("resourceid"));
            baseBean.writeLog(">>>>>>computeSalary_Ajax.jsp>>>>>resourceid=" + resourceid);
            String kqkxhj = "0";
            //1.倒班补贴
            String dbbtKey = Util.null2String(columnJson.getString("dbbt"));
            if ("UNLOCK".equalsIgnoreCase(dbbtKey)) {
                String dbbt = computeDbbt(paramJson);
                resultJson.put("dbbt", "倒班补贴=" + dbbt);
                updateSalaryResult(dbbt, id, resourceid, "1685372097244");
            }
            //2.免休补助
            String mxbtKey = Util.null2String(columnJson.getString("mxbt"));
            if ("UNLOCK".equalsIgnoreCase(mxbtKey)) {
                String mxbt = computeMxbz(paramJson);
                resultJson.put("mxbt", "免休补助=" + mxbt);
                updateSalaryResult(mxbt, id, resourceid, "1685457697632");
            }
            //3.标准薪资合计
            String bzgzhjKey = Util.null2String(columnJson.getString("bzgzhj"));
            if ("UNLOCK".equalsIgnoreCase(bzgzhjKey)) {
                String bzgzhj = computeBzgzhj(paramJson);
                resultJson.put("bzgzhj", "标准薪资合计=" + bzgzhj);
                updateSalaryResult(bzgzhj, id, resourceid, "1685393314306");
            }
            //4.旷工扣款
            String kgkkKey = Util.null2String(columnJson.getString("kgkk"));
            if ("UNLOCK".equalsIgnoreCase(kgkkKey)) {
                String kgkk = computeKgkk(paramJson);
                kqkxhj = fAdd(kgkk, kqkxhj);
                resultJson.put("kgkk", "旷工扣款=" + kgkk);
                updateSalaryResult(kgkk, id, resourceid, "1686028676893");
            }
            //5.事假扣除
            String sjkcKey = Util.null2String(columnJson.getString("sjkc"));
            if ("UNLOCK".equalsIgnoreCase(sjkcKey)) {
                String sjkc = computeSjkc(paramJson);
                kqkxhj = fAdd(kqkxhj, sjkc);
                resultJson.put("sjkc", "事假扣除=" + sjkc);
                updateSalaryResult(sjkc, id, resourceid, "1686034175111");
            }
            //6.病假扣除
            String bjkcKey = Util.null2String(columnJson.getString("bjkc"));
            if ("UNLOCK".equalsIgnoreCase(bjkcKey)) {
                String bjkc = computeBjkc(paramJson);
                kqkxhj = fAdd(kqkxhj, bjkc);
                resultJson.put("bjkc", "病假扣除=" + bjkc);
                updateSalaryResult(bjkc, id, resourceid, "1686034165433");
            }
            //7.产假工资扣款
            String cjgzkkKey = Util.null2String(columnJson.getString("cjgzkk"));
            if ("UNLOCK".equalsIgnoreCase(cjgzkkKey)) {
                String cjgzkk = computeCjgzkk(paramJson);
                kqkxhj = fAdd(kqkxhj, cjgzkk);
                resultJson.put("cjgzkk", "产假工资扣款=" + cjgzkk);
                updateSalaryResult(cjgzkk, id, resourceid, "1686034194909");
            }
            //考勤扣项合计
            String kqkxhjKey = Util.null2String(columnJson.getString("kqkxhj"));
            if ("UNLOCK".equalsIgnoreCase(kqkxhjKey)) {
                String bqkkk = paramJson.getString("bqkkk");//补缺卡扣款
                String cdztkk = paramJson.getString("cdztkk");//迟到早退扣款
                String gjjtzkk = paramJson.getString("gjjtzkk");//公积金调整扣款
                String qtkk = paramJson.getString("qtkk");//其他扣款
                String kqkxhj1 = fAdd(fAdd(fAdd(bqkkk, cdztkk), gjjtzkk), qtkk);
                kqkxhj = fAdd(kqkxhj, kqkxhj1);
                resultJson.put("kqkxhj", "考勤扣项合计=" + kqkxhj);
                updateSalaryResult(kqkxhj, id, resourceid, "1685393062388");
            }
        }

    } catch (Exception e) {
        baseBean.writeLog(">>>>>>computeSalary_Ajax.jsp>>>>>后端接收数据异常" + e);
        e.printStackTrace();
    }
    baseBean.writeLog(">>>>>>computeSalary_Ajax.jsp>>>>>执行结束");
    baseBean.writeLog(">>>>>>computeSalary_Ajax.jsp>>>>>resultJson=" + resultJson);
    out.print(resultJson.toJSONString());
%>
<%!


    private static BaseBean baseBean = new BaseBean();
    private static RecordSet rs = new RecordSet();

    /**
     * 更新加密计算结果
     */
    private static boolean updateSalaryResult(String resultValue, String id, String resourceid, String fieldid) {
        String encryptResultValue = AESEncryptUtil.encrypt(resultValue);
        //RecordSet rs = new RecordSet();
        String sql = "update hrsa_salary_acct_result set result_value=? where salary_acct_record_id=? and employee_id=? and salary_item_id=?";
        baseBean.writeLog(">>>>>>updateSalaryResult>>>>sql=" + sql + ",encryptResultValue=" + encryptResultValue + ",id=" + id + ",resourceid=" + resourceid + ",fieldid=" + fieldid);
        return rs.executeUpdate(sql, encryptResultValue, id, resourceid, fieldid);
    }

    /**
     * 计算倒班补贴计算规则：核算月的中班次数*60+夜班次数*80
     */
    private static String computeDbbt(JSONObject params) {
        String dbbtje = "0.00";
        String resourceid = Util.null2String(params.getString("resourceid"));
        String yearMonth = Util.null2String(params.getString("yearMonth"));
        try {
            String zbts = Util.null2String(getKqZbbcTs(resourceid, yearMonth));
            String ybts = Util.null2String(getKqYbbcTs(resourceid, yearMonth));
            baseBean.writeLog(">>>>>>computeDbbt>>>>zbts=" + zbts + ",ybts=" + ybts);
            dbbtje = fAdd(fMultiply(zbts, "60",4), fMultiply(ybts, "80",4));
        } catch (Exception e) {
            e.printStackTrace();
            baseBean.writeLog("当月计算倒班补贴异常");
        }
        baseBean.writeLog(">>>>>>computeDbbt>>>>dbbtje=" + dbbtje);
        return dbbtje;
    }

    /**
     * 当月计算免休补助针对弹性考勤人员：基本工资/应出勤天数*考勤弹性未休天数
     */
    private static String computeMxbz(JSONObject params) {
        String mxbtje = "0.00";
        String resourceid = Util.null2String(params.getString("resourceid"));
        String yearMonth = Util.null2String(params.getString("yearMonth"));
        String jbgz = Util.null2String(params.getString("jbgz"));
        String ycqts = "25";
        baseBean.writeLog(">>>>>>computeMxbz>>>>jbgz=" + jbgz + ",ycqts=" + ycqts);
        try {
            String zzrx = fDivide(jbgz, ycqts,4);//转正日薪
            String mxts = getMxts(resourceid, yearMonth);
            baseBean.writeLog(">>>>>>computeMxbz>>>>zzrx=" + zzrx + ",mxts=" + mxts);
            mxbtje = fMultiply(zzrx, mxts,4);
        } catch (Exception e) {
            e.printStackTrace();
            baseBean.writeLog("当月计算免休补助异常");
        }
        baseBean.writeLog(">>>>>>computeMxbz>>>>mxbtje=" + mxbtje);
        return mxbtje;
    }

    /**
     * 试用：标准薪资合计=试用期：试用期工资/应出勤天数*实际应出勤天数
     * 正式：标准薪资合计=正式：转正工资/应出勤天数*实际应出勤天数
     * 试用转正式：转正：（试用期工资/应出勤天数*实际试用期应出勤天数）+（转正工资/应出勤天数*实际正式应出勤天数）
     */
    private static String computeBzgzhj(JSONObject params) {
        String bzgzhj = "0.00";
        String resourceid = Util.null2String(params.getString("resourceid"));
        String yearMonth = Util.null2String(params.getString("yearMonth"));
        String zzxz = Util.null2String(params.getString("zzxz"));
        String syqgz = Util.null2String(params.getString("syqgz"));
        String ycqts = Util.null2String(params.getString("ycqts"));
        String zzrq = Util.null2String(params.getString("zzrq"));
        String lzrq = Util.null2String(params.getString("lzrq"));
        String rzrq = Util.null2String(params.getString("rzrq"));
        try {
            String userStatus = getUserStatus(params);
            baseBean.writeLog(">>>>>>computeBzgzhj>>>>userStatus=" + userStatus);

            //试用员工未离职：标准薪资合计=试用期工资工资/应出勤天数*试用期间应出勤天数
            if ("0".equals(userStatus)) {
                bzgzhj = syqgz;
            }
            //正式员工未离职：标准薪资合计=转正工资/应出勤天数*正式期间应出勤天数
            if ("2".equals(userStatus)) {
                bzgzhj = zzxz;
            }
            //当月试用期转正式员工未离职：（转正工资/应出勤天数*正式期间应出勤天数）+（试用期工资工资/应出勤天数*试用期间应出勤天数）
            if ("1".equals(userStatus)) {
                String zzrx = fDivide(zzxz, ycqts,4);//转正日薪
                String syrx = fDivide(syqgz, ycqts,4);//试用日薪
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>zzrx=" + zzrx + ",syrx=" + syrx);
                String sjycqts = getSjYcqts(resourceid, yearMonth);
                String syqts = getSyqkqts(zzrq, resourceid, yearMonth);
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>sjycqts=" + sjycqts + ",syqts=" + syqts);
                String zzhcqts = fSubtract(sjycqts, syqts);
                JSONObject jjrJson = getKqJjrts(yearMonth, rzrq, lzrq, zzrq);
                String syqjjrts = jjrJson.getString("syqjjrts");
                String zsjjrts = jjrJson.getString("zsjjrts");
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>syqjjrts=" + syqjjrts + ",zsjjrts=" + zsjjrts);
                syqts = fAdd(syqts, syqjjrts);
                zzhcqts = fAdd(zzhcqts, zsjjrts);
                String xzhj_sy = fMultiply(syrx, syqts,4);
                String xzhj_zz = fMultiply(zzrx, zzhcqts,4);
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>zzhcqts=" + zzhcqts);
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>xzhj_sy=" + xzhj_sy + ",xzhj_zz=" + xzhj_zz);
                bzgzhj = fAdd(xzhj_sy, xzhj_zz);
            }
            //当月试用期员工离职
            if ("3".equals(userStatus)) {
                String syrx = fDivide(syqgz, ycqts,4);//试用日薪
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>syrx=" + syrx);
                String syqts = getLzqkqts(lzrq, resourceid, yearMonth);
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>syqts=" + syqts);
                JSONObject jjrJson = getKqJjrts(yearMonth, rzrq, lzrq, zzrq);
                String syqjjrts = jjrJson.getString("syqjjrts");
                String zsjjrts = jjrJson.getString("zsjjrts");
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>syqjjrts=" + syqjjrts + ",zsjjrts=" + zsjjrts);
                syqts = fAdd(syqts, syqjjrts);
                bzgzhj = fMultiply(syrx, syqts,4);
            }
            //当月试用期转正式员工后离职
            if ("5".equals(userStatus)) {
                String zzrx = fDivide(zzxz, ycqts,4);//转正日薪
                String syrx = fDivide(syqgz, ycqts,4);//试用日薪
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>zzrx=" + zzrx + ",syrx=" + syrx);
                String syqts = getSyqkqts(zzrq, resourceid, yearMonth);
                String zzhts = getLzqkqts(lzrq, resourceid, yearMonth);
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>syqts=" + syqts + ",zzhts=" + zzhts);
                String zzhcqts = fSubtract(zzhts, syqts);
                JSONObject jjrJson = getKqJjrts(yearMonth, rzrq, lzrq, zzrq);
                String syqjjrts = jjrJson.getString("syqjjrts");
                String zsjjrts = jjrJson.getString("zsjjrts");
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>syqjjrts=" + syqjjrts + ",zsjjrts=" + zsjjrts);
                syqts = fAdd(syqts, syqjjrts);
                zzhcqts = fAdd(zzhcqts, zsjjrts);
                String xzhj_sy = fMultiply(syrx, syqts,4);
                String xzhj_zz = fMultiply(zzrx, zzhcqts,4);
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>zzhcqts=" + zzhcqts);
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>xzhj_sy=" + xzhj_sy + ",xzhj_zz=" + xzhj_zz);
                bzgzhj = fAdd(xzhj_sy, xzhj_zz);
            }
            //当月正式员工离职
            if ("6".equals(userStatus)) {
                String zzrx = fDivide(zzxz, ycqts,4);//转正日薪
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>zzrx=" + zzrx);
                String syqts = getLzqkqts(lzrq, resourceid, yearMonth);
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>syqts=" + syqts);
                JSONObject jjrJson = getKqJjrts(yearMonth, rzrq, lzrq, zzrq);
                String syqjjrts = jjrJson.getString("syqjjrts");
                String zsjjrts = jjrJson.getString("zsjjrts");
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>syqjjrts=" + syqjjrts + ",zsjjrts=" + zsjjrts);
                syqts = fAdd(fAdd(syqts, zsjjrts),syqjjrts);
                if(Util.getDoubleValue(syqts)==Util.getDoubleValue(ycqts)){
                    bzgzhj = zzxz;
                }else {
                    bzgzhj = fMultiply(zzrx, syqts,4);
                }
            }
            //当月入职未离职
            if ("7".equals(userStatus)) {
                String syrx = fDivide(syqgz, ycqts,4);//试用日薪
                baseBean.writeLog(">>>>>>cy----computeBzgzhj>>>>ycqts=" + ycqts);
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>syrx=" + syrx);
                String sjycqts = getRzqkqts(rzrq,resourceid, yearMonth);
                baseBean.writeLog(">>>>>>cy----computeBzgzhj>>>>sjycqts=" + sjycqts);
                JSONObject jjrJson = getKqJjrts(yearMonth, rzrq, lzrq, zzrq);
                String syqjjrts = jjrJson.getString("syqjjrts");
                String zsjjrts = jjrJson.getString("zsjjrts");
                baseBean.writeLog(">>>>>>computeBzgzhj>>>>syqjjrts=" + syqjjrts + ",zsjjrts=" + zsjjrts);
                sjycqts = fAdd(fAdd(sjycqts, zsjjrts),syqjjrts);
                if(Util.getDoubleValue(sjycqts)==Util.getDoubleValue(ycqts)){
                    bzgzhj = syqgz;
                }else {
                    bzgzhj = fMultiply(syrx, sjycqts,4);
                }

            }
            baseBean.writeLog(">>>>>>cy---computeBzgzhj>>>>bzgzhj=" + bzgzhj);
        } catch (Exception e) {
            e.printStackTrace();
            baseBean.writeLog("当月试用期工资扣款异常");
        }
        baseBean.writeLog(">>>>>>computeBzgzhj>>>>bzgzhj=" + bzgzhj);
        return bzgzhj;
    }


    /**
     * 旷工扣款
     */
    private static String computeKgkk(JSONObject params) {
        String kgkk = "0.00";
        String resourceid = Util.null2String(params.getString("resourceid"));
        String yearMonth = Util.null2String(params.getString("yearMonth"));
        String zzxz = Util.null2String(params.getString("zzxz"));
        String syqgz = Util.null2String(params.getString("syqgz"));
        String ycqts = Util.null2String(params.getString("ycqts"));
        String kgts = Util.null2String(params.getString("kgts"));
        String zzrq = Util.null2String(params.getString("zzrq"));
        String lzrq = Util.null2String(params.getString("lzrq"));
        String rzrq = Util.null2String(params.getString("rzrq"));
        try {
            String userStatus = getUserStatus(params);
            String zzrx = fDivide(zzxz, ycqts,4);//转正日薪
            String syrx = fDivide(syqgz, ycqts,4);//试用日薪
            baseBean.writeLog(">>>>>>computeKgkk>>>>userStatus=" + userStatus + ",zzrx=" + zzrx + ",syrx=" + syrx);
            //试用状态：转正月薪*0.8/应出勤天数*旷工次数+200*旷工次数
            if ("0".equals(userStatus) && Util.getDoubleValue(kgts)>0) {
                kgkk = fAdd(fMultiply(syrx, kgts,4), fMultiply("200", "0"));
            }
            //正式状态：转正月薪/应出勤天数*旷工次数+200*旷工次数
            if ("2".equals(userStatus) && Util.getDoubleValue(kgts)>0) {
                kgkk = fAdd(fMultiply(zzrx, kgts,4), fMultiply("200", "0"));
            }
            //当月试用转正（转正月薪*0.8/应出勤天数*试用矿工天数+200*试用旷工次数）+（转正转正月薪/应出勤天数*矿工天数+200*旷工次数）
            if ("1".equals(userStatus) && Util.getDoubleValue(kgts)>0) {
                String syqkgts = getSyqkgts(zzrq, resourceid, yearMonth);
                String zzhkgts = fSubtract(kgts, syqkgts);
                baseBean.writeLog(">>>>>>computeKgkk>>>>syqkgts=" + syqkgts + ",zzhkgts=" + zzhkgts);
                String kgkk_sy = fAdd(fMultiply(syrx, syqkgts,4), fMultiply("200", "0"));
                String kgkk_zz = fAdd(fMultiply(zzrx, zzhkgts,4), fMultiply("200", "0"));
                baseBean.writeLog(">>>>>>computeKgkk>>>>kgkk_sy=" + kgkk_sy + ",kgkk_zz=" + kgkk_zz);
                kgkk = fAdd(kgkk_sy, kgkk_zz);
            }
            //当月试用离职（转正月薪/应出勤天数*试用矿工天数）
            if ("3".equals(userStatus) && Util.getDoubleValue(kgts)>0) {
                String syqkgts = getSyqkgts(lzrq, resourceid, yearMonth);
                baseBean.writeLog(">>>>>>computeKgkk>>>>syqkgts=" + syqkgts + ",syrx=" + syrx);
                kgkk = fAdd(fMultiply(syrx, syqkgts,4), fMultiply("200", "0"));
            }
            //当月转正后离职（转正月薪*0.8/应出勤天数*试用矿工天数）+转正月薪/应出勤天数*矿工天数）
            if ("5".equals(userStatus) && Util.getDoubleValue(kgts)>0) {
                String kqkgts = getKqKgts(resourceid, yearMonth);
                if (kqkgts.equals(kgts)) {
                    String syqkgts = getSyqkgts(zzrq, resourceid, yearMonth);
                    String lzqkgts = getSyqkgts(lzrq, resourceid, yearMonth);
                    String zzqkgts = fSubtract(lzqkgts, syqkgts);
                    baseBean.writeLog(">>>>>>computeKgkk>>>>syqkgts=" + syqkgts + ",lzqkgts=" + lzqkgts + ",zzqkgts=" + zzqkgts);
                    String kgkk_sy = fAdd(fMultiply(syrx, syqkgts,4), fMultiply("200", "0"));
                    String kgkk_zz = fAdd(fMultiply(zzrx, zzqkgts,4), fMultiply("200", "0"));
                    baseBean.writeLog(">>>>>>computeKgkk>>>>kgkk_sy=" + kgkk_sy + ",kgkk_zz=" + kgkk_zz);
                    kgkk = fAdd(kgkk_sy, kgkk_zz);
                } else {
                    String kgkk_sy = fAdd(fMultiply(syrx, "0",4), fMultiply("200", "0"));
                    String kgkk_zz = fAdd(fMultiply(zzrx, kgts,4), fMultiply("200", "0"));
                    baseBean.writeLog(">>>>>>computeKgkk>>>>kgkk_sy=" + kgkk_sy + ",kgkk_zz=" + kgkk_zz);
                    kgkk = fAdd(kgkk_sy, kgkk_zz);
                }

            }
            //正式员工当月离职（转正月薪/应出勤天数*事假天数）
            if ("6".equals(userStatus) && Util.getDoubleValue(kgts)>0) {
                kgkk = fMultiply(zzrx, kgts,4);
            }
            //当月入职未离职
            if ("7".equals(userStatus) && Util.getDoubleValue(kgts)>0) {
                baseBean.writeLog(">>>>>>computeKgkk>>>>syrx=" + syrx);
                // String sjycqts = getSyqkgts(rzrq,resourceid, yearMonth);
                kgkk = fMultiply(syrx, kgts,4);
            }
        } catch (Exception e) {
            e.printStackTrace();
            baseBean.writeLog("旷工扣款计算异常");
        }
        baseBean.writeLog(">>>>>>computeKgkk>>>>kgkk=" + kgkk);
        return kgkk;
    }

    /**
     * 事假扣除
     */
    private static String computeSjkc(JSONObject params) {
        String sjkk = "0.00";
        String resourceid = Util.null2String(params.getString("resourceid"));
        String yearMonth = Util.null2String(params.getString("yearMonth"));
        String zzxz = Util.null2String(params.getString("zzxz"));
        String syqgz = Util.null2String(params.getString("syqgz"));
        String ycqts = Util.null2String(params.getString("ycqts"));
        String sjts = Util.null2String(params.getString("sjts"));
        String zzrq = Util.null2String(params.getString("zzrq"));
        String lzrq = Util.null2String(params.getString("lzrq"));
        String rzrq = Util.null2String(params.getString("rzrq"));
        try {
            String userStatus = getUserStatus(params);
            String zzrx = fDivide(zzxz, ycqts,4);//转正日薪
            String syrx = fDivide(syqgz, ycqts,4);//试用日薪
            baseBean.writeLog(">>>>>>computeSjkc>>>>userStatus=" + userStatus + ",zzrx=" + zzrx + ",syrx=" + syrx);
            //试用状态：事假扣除 = 转正薪资 * 0.8 / 应出勤天数 * 事假天数
            if ("0".equals(userStatus) && Util.getDoubleValue(sjts)>0) {
                sjkk = fMultiply(syrx, sjts,4);
            }
            //正式状态：事假扣除 = 转正薪资 / 应出勤天数 * 事假天数
            if ("2".equals(userStatus) && Util.getDoubleValue(sjts)>0) {
                sjkk = fMultiply(zzrx, sjts,4);
            }
            //当月试用（转正月薪*0.8/应出勤天数*试用事假天数）+（转正转正月薪/应出勤天数*事假天数）
            if ("1".equals(userStatus) && Util.getDoubleValue(sjts)>0) {
                String syqsjts = getSyqsjts(zzrq, resourceid, yearMonth);
                String zzhsjts = fSubtract(sjts, syqsjts);
                String sjkk_sy = fMultiply(syrx, syqsjts,4);
                String sjkk_zz = fMultiply(zzrx, zzhsjts,4);
                baseBean.writeLog(">>>>>>computeSjkc>>>>syqsjts=" + syqsjts + ",zzhsjts=" + zzhsjts);
                sjkk = fAdd(sjkk_sy, sjkk_zz);
            }
            //当月试用离职（转正月薪/应出勤天数*试用事假天数）
            if ("3".equals(userStatus) && Util.getDoubleValue(sjts)>0) {
                //String syqsjts = getSyqsjts(lzrq, resourceid, yearMonth);
                sjkk = fMultiply(syrx, sjts,4);
                baseBean.writeLog(">>>>>>computeSjkc>>>>sjts=" + sjts + ",sjkk=" + sjkk + ",syrx=" + syrx);
            }
            //当月转正后离职（转正月薪*0.8/应出勤天数*试用事假天数）+转正月薪/应出勤天数*事假天数）
            if ("5".equals(userStatus) && Util.getDoubleValue(sjts)>0) {
                String kqsjts = getKqSjts(resourceid, yearMonth);
                if (kqsjts.equals(sjts)) {
                    String syqsjts = getSyqsjts(zzrq, resourceid, yearMonth);
                    String lzqsjts = getSyqsjts(lzrq, resourceid, yearMonth);
                    String zzhsjts = fSubtract(lzqsjts, syqsjts);
                    baseBean.writeLog(">>>>>>computeSjkc>>>>syqsjts=" + syqsjts + ",lzqsjts=" + lzqsjts + ",zzhsjts=" + zzhsjts);
                    String sjkk_sy = fMultiply(syrx, syqsjts,4);
                    String sjkk_zz = fMultiply(zzrx, zzhsjts,4);
                    baseBean.writeLog(">>>>>>computeSjkc>>>>sjkk_sy=" + sjkk_sy + ",sjkk_zz=" + sjkk_zz);
                    sjkk = fAdd(sjkk_sy, sjkk_zz);
                } else {
                    String sjkk_sy = fMultiply(syrx, "0",4);
                    String sjkk_zz = fMultiply(zzrx, sjts,4);
                    baseBean.writeLog(">>>>>>computeSjkc>>>>sjkk_sy=" + sjkk_sy + ",sjkk_zz=" + sjkk_zz);
                    sjkk = fAdd(sjkk_sy, sjkk_zz);
                }

            }
            //正式员工当月离职（转正月薪/应出勤天数*事假天数）
            if ("6".equals(userStatus) && Util.getDoubleValue(sjts)>0) {
                sjkk = fMultiply(zzrx, sjts,4);
            }
            //当月入职未离职
            if ("7".equals(userStatus) && Util.getDoubleValue(sjts)>0) {
                baseBean.writeLog(">>>>>>computeSjkc>>>>syrx=" + syrx);
                // String sjycqts = getSyqsjts(rzrq,resourceid, yearMonth);
                sjkk = fMultiply(syrx, sjts,4);
            }
        } catch (Exception e) {
            e.printStackTrace();
            baseBean.writeLog("事假扣除计算异常");
        }
        baseBean.writeLog(">>>>>>computeSjkc>>>>sjkk=" + sjkk);
        return sjkk;
    }

    /**
     * 病假扣除 转正月薪/应出勤天数*当月病假天数*对应扣款比例
     */
    private static String computeBjkc(JSONObject params) {
        String bjkk = "0.00";
        String resourceid = Util.null2String(params.getString("resourceid"));
        String yearMonth = Util.null2String(params.getString("yearMonth"));
        String zzxz = Util.null2String(params.getString("zzxz"));
        String syqgz = Util.null2String(params.getString("syqgz"));
        String ycqts = Util.null2String(params.getString("ycqts"));
        String bjts = Util.null2String(params.getString("bjts"));
        String zzrq = Util.null2String(params.getString("zzrq"));
        String lzrq = Util.null2String(params.getString("lzrq"));
        String rzrq = Util.null2String(params.getString("rzrq"));
        try {
            String userStatus = getUserStatus(params);
            String zzrx = fDivide(zzxz, ycqts,4);//转正日薪
            String syrx = fDivide(syqgz, ycqts,4);//试用日薪
            String kkbl = getKkbl(resourceid, yearMonth, bjts);
            baseBean.writeLog(">>>>>>computeBjkc>>>>userStatus=" + userStatus + ",zzrx=" + zzrx + ",syrx=" + syrx);
            baseBean.writeLog(">>>>>>computeBjkc>>>>kkbl=" + kkbl);
            //试用状态：转正月薪*0.8/应出勤天数*当月病假天数*对应扣款比例
            if ("0".equals(userStatus) && Util.getDoubleValue(bjts)>0) {
                bjkk = fMultiply(fMultiply(syrx, bjts,4), kkbl,4);
            }
            //正式状态：转正月薪/应出勤天数*当月病假天数*对应扣款比例
            if ("2".equals(userStatus) && Util.getDoubleValue(bjts)>0) {
                bjkk = fMultiply(fMultiply(zzrx, bjts,4), kkbl,4);
            }
            //当月试用（转正月薪*0.8/应出勤天数*当月病假天数*对应扣款比例）+（转正转正月薪/应出勤天数*当月病假天数*对应扣款比例）
            if ("1".equals(userStatus) && Util.getDoubleValue(bjts)>0) {
                if (Util.getDoubleValue(bjts) > 0) {
                    String syqbjts = getSyqbjts(zzrq, resourceid, yearMonth);
                    String zzhbjts = fSubtract(bjts, syqbjts);
                    String bjkk_sy = fMultiply(fMultiply(syrx, syqbjts,4), kkbl,4);
                    String bjkk_zz = fMultiply(fMultiply(zzrx, zzhbjts,4), kkbl,4);
                    baseBean.writeLog(">>>>>>computeBjkc>>>>syqbjts=" + syqbjts + ",zzhbjts=" + zzhbjts);
                    baseBean.writeLog(">>>>>>computeBjkc>>>>bjkk_sy=" + bjkk_sy + ",bjkk_zz=" + bjkk_zz);
                    bjkk = fAdd(bjkk_sy, bjkk_zz);
                }
            }
            //当月试用离职（转正月薪/应出勤天数*当月病假天数*对应扣款比例）
            if ("3".equals(userStatus) && Util.getDoubleValue(bjts)>0) {
                String syqbjts = getSyqbjts(lzrq, resourceid, yearMonth);
                bjkk = fMultiply(fMultiply(syrx, syqbjts,4), kkbl,4);
                baseBean.writeLog(">>>>>>computeBjkc>>>>syqbjts=" + syqbjts + ",bjkk=" + bjkk + ",syrx=" + syrx);
            }
            //当月转正后离职（转正月薪*0.8/应出勤天数*当月病假天数*对应扣款比例）+转正月薪/应出勤天数*当月病假天数*对应扣款比例）
            if ("5".equals(userStatus) && Util.getDoubleValue(bjts)>0) {
                String kqbjts = getKqBjts(resourceid, yearMonth);
                if (kqbjts.equals(bjts)) {
                    String syqbjts = getSyqbjts(zzrq, resourceid, yearMonth);
                    String lzqbjts = getSyqbjts(lzrq, resourceid, yearMonth);
                    String zzhbjts = fSubtract(lzqbjts, syqbjts);
                    baseBean.writeLog(">>>>>>computeBjkc>>>>syqbjts=" + syqbjts + ",lzqbjts=" + lzqbjts + ",zzhbjts=" + zzhbjts);
                    String bjkk_sy = fMultiply(fMultiply(syrx, syqbjts,4), kkbl,4);
                    String bjkk_zz = fMultiply(fMultiply(zzrx, zzhbjts,4), kkbl,4);
                    baseBean.writeLog(">>>>>>computeBjkc>>>>bjkk_sy=" + bjkk_sy + ",bjkk_zz=" + bjkk_zz);
                    bjkk = fAdd(bjkk_sy, bjkk_zz);
                } else {
                    String bjkk_sy = fMultiply(fMultiply(syrx, "0",4), kkbl,4);
                    String bjkk_zz = fMultiply(fMultiply(zzrx, bjts,4), kkbl,4);
                    baseBean.writeLog(">>>>>>computeBjkc>>>>bjkk_sy=" + bjkk_sy + ",bjkk_zz=" + bjkk_zz);
                    bjkk = fAdd(bjkk_sy, bjkk_zz);
                }

            }
            //正式员工当月离职（转正月薪/应出勤天数*事假天数）
            if ("6".equals(userStatus) && Util.getDoubleValue(bjts)>0) {
                bjkk = fMultiply(fMultiply(zzrx, bjts,4), kkbl,4);
            }
            //当月入职未离职
            if ("7".equals(userStatus) && Util.getDoubleValue(bjts)>0) {
                baseBean.writeLog(">>>>>>computeBjkc>>>>syrx=" + syrx);
                // String sjycqts = getSyqbjts(rzrq,resourceid, yearMonth);
                bjkk = fMultiply(fMultiply(syrx, bjts,4), kkbl,4);
            }
        } catch (Exception e) {
            e.printStackTrace();
            baseBean.writeLog("病假扣除计算异常");
        }
        baseBean.writeLog(">>>>>>computeBjkc>>>>bjkk=" + bjkk);
        return bjkk;
    }

    /**
     * 产假工资扣款 仅针对休产假的女员工：（职级工资+保密津贴+基础绩效）/应出勤天数*当月产假天数
     * (当月产假天数<=应出勤天数，大于应出勤天数时按照应出勤天数计算)
     */

    private static String computeCjgzkk(JSONObject params) {
        String cjkk = "0.00";
        String resourceid = Util.null2String(params.getString("resourceid"));
        String yearMonth = Util.null2String(params.getString("yearMonth"));
        String zjgz = Util.null2String(params.getString("zjgz"));
        String ycqts = Util.null2String(params.getString("ycqts"));
        String bmjt = Util.null2String(params.getString("bmjt"));
        String jcjx = Util.null2String(params.getString("jcjx"));
        String zzrq = Util.null2String(params.getString("zzrq"));
        String lzrq = Util.null2String(params.getString("lzrq"));
        try {
            String userStatus = getUserStatus(params);
            String zzrx = fDivide(fAdd(fAdd(zjgz, bmjt), jcjx), ycqts,4);//转正日薪
            String cjts = getdycjts(resourceid, yearMonth);
            baseBean.writeLog(">>>>>>computeCjgzkk>>>>userStatus=" + userStatus + ",zzrx=" + zzrx + ",cjts=" + cjts);
            //正式状态：(职级工资+保密津贴+基础绩效）/应出勤天数*当月产假天数
            cjkk = fMultiply(zzrx, cjts,4);
            //当月转离职（职级工资+保密津贴+基础绩效）/应出勤天数*(当月离职前产假天数)）
            if ("5".equals(userStatus)) {
                String lzqcjts = getSyqcjts(lzrq, resourceid, yearMonth);
                cjkk = fMultiply(zzrx, lzqcjts,4);
                baseBean.writeLog(">>>>>>computeCjgzkk>>>>lzqcjts=" + lzqcjts + ",cjkk=" + cjkk);

            }
        } catch (Exception e) {
            e.printStackTrace();
            baseBean.writeLog("产假工资扣款计算异常");
        }
        baseBean.writeLog(">>>>>>computeCjgzkk>>>>cjkk=" + cjkk);
        return cjkk;
    }

    /**
     * 当月获取夜班天数
     */
    private static String getKqYbbcTs(String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        rs.executeQuery("select count(id) from kq_shiftschedule where groupid=6 and serialid=7 " +
                "and left(kqdate,7)=? and resourceid=?", yearMonth, resourceid);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 当月获取中班天数
     */
    private static String getKqZbbcTs(String resourceid, String yearMonth) {
        // RecordSet rs = new RecordSet();
        rs.executeQuery("select count(id) from kq_shiftschedule where groupid=6 and serialid=6 " +
                "and left(kqdate,7)=? and resourceid=?", yearMonth, resourceid);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取当月免休天数
     */
    private static String getMxts(String resourceid, String yearMonth) {
        // RecordSet rs = new RecordSet();
        String sql = "select syye from uf_ryjqyejdb where xm=? and left(rq,7)=?";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取人员状态
     */
    private static String getUserStatus(JSONObject params) {
        String yearMonth = Util.null2String(params.getString("yearMonth"));
        String rzrq = Util.null2String(params.getString("rzrq"));
        String zzrq = Util.null2String(params.getString("zzrq"));
        String lzrq = Util.null2String(params.getString("lzrq"));
        String status = "0";//试用期员工未离职
        if (!"".equals(zzrq) && "".equals(lzrq)) {//转正/未离职
            int result = compareToYearMonth(zzrq, yearMonth);
            if (result < 0) {
                status = "2";//已经是正式员工
            }
            if (result == 0) {//是否当月试用期转正
                status = "1";//当月试用期转正式员工
            }
            if (result > 0) {
                status = "0";//未到转正日期预转正式员工
            }
        }
        if ("".equals(zzrq) && !"".equals(lzrq)) {//试用期/离职
            int result = compareToYearMonth(lzrq, yearMonth);
            if (result < 0) {
                status = "4";//已经离职
            }
            if (result == 0) {//是否当月试用期离职
                status = "3";//当月试用期员工离职
            }
            if (result > 0) {//试用期预离职
                String rzyf = rzrq.substring(0, 7);
                if (rzyf.equals(yearMonth)) {//是否当月入职
                    status = "7";//当月入职试用期员工
                } else {
                    status = "0";//试用期预离职
                }
            }
        }
        if (!"".equals(lzrq) && !"".equals(zzrq)) {//正式/离职
            int result1 = compareToYearMonth(zzrq, yearMonth);
            int result2 = compareToYearMonth(lzrq, yearMonth);
            if (result2 < 0) {
                status = "4";//已经离职
            }
            if (result1 < 0 && result2 == 0) {
                status = "6";//当月正式员工离职
            }
            if (result1 == 0 && result2 == 0) {
                status = "5";//当月试用期转正式员工后离职
            }
            if (result1 > 0 && result2 == 0) {
                status = "3";//当月试用期离职
            }
            if (result1 < 0 && result2 > 0) {
                status = "2";//正式员工预离职
            }
            if (result1 == 0 && result2 > 0) {
                status = "1";//当月试用期转正式员工预离职
            }
            if (result1 > 0 && result2 > 0) {
                status = "0";//试用期预转正预离职
            }
        }
        if ("".equals(zzrq) && "".equals(lzrq)) {//未转正/未离职
            String rzyf = rzrq.substring(0, 7);
            if (rzyf.equals(yearMonth)) {//是否当月入职
                status = "7";//当月入职试用期员工
            }
        }
        return status;
    }
    /**
     * 获取当月入职试用期考勤天数
     */
    private static String getRzqkqts(String rzrq, String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        String sql = "select count(resourceid) from kq_format_total where resourceid=? " +
                " and workdays=1 and left(kqdate,7)=? and kqdate>='" + rzrq + "'";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }
    /**
     * 获取当月转正前试用期考勤天数
     */
    private static String getSyqkqts(String zzrq, String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        String sql = "select count(resourceid) from kq_format_total where resourceid=? " +
                " and workdays=1 and left(kqdate,7)=? and kqdate<'" + zzrq + "'";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取当月离职前考勤天数
     */
    private static String getLzqkqts(String lzrq, String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        String sql = "select count(resourceid) from kq_format_total where resourceid=? " +
                " and workdays=1 and left(kqdate,7)=? and kqdate<='" + lzrq + "'";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取当月转正/离职前试用期矿工天数
     */
    private static String getSyqkgts(String rq, String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        String sql = "select count(resourceid) from kq_format_total where resourceid=? " +
                "and kqdate<='" + rq + "' and workdays=1 and absenteeism=1 and left(kqdate,7)=?";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取当月转正/离职前试用期事假天数
     */
    private static String getSyqsjts(String rq, String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        String sql = "select sum(b.duration) from kq_format_total a " +
                "join kq_flow_split_leave b on a.resourceid=b.resourceid and a.kqdate=b.fromdate and a.kqdate=b.todate " +
                "where b.newleavetype=6 and ifnull(a.workdays,'') !='' and ifnull(a.attendancedays,0)=0 " +
                "and ifnull(a.leaveMins,0)>0 and a.resourceid=? and left(kqdate,7)=? and kqdate<='" + rq + "'";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取当月转正/离职前试用期病假天数
     */
    private static String getSyqbjts(String rq, String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        String sql = "select count(a.resourceid) from kq_format_total a " +
                "join kq_flow_split_leave b on a.resourceid=b.resourceid and a.kqdate=b.fromdate and a.kqdate=b.todate " +
                "where b.newleavetype=7 and ifnull(a.workdays,'') !='' and ifnull(a.attendancedays,0)=0 " +
                "and ifnull(a.leaveMins,0)>0 and a.resourceid=? and left(kqdate,7)=? and kqdate<='" + rq + "'";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取当月转正/离职前试用期产假天数
     */
    private static String getSyqcjts(String rq, String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        String sql = "select count(a.resourceid) from kq_format_total a " +
                "join kq_flow_split_leave b on a.resourceid=b.resourceid and a.kqdate=b.fromdate and a.kqdate=b.todate " +
                "where b.newleavetype=8 and ifnull(a.workdays,'') !='' and ifnull(a.attendancedays,0)=0 " +
                "and ifnull(a.leaveMins,0)>0 and a.resourceid=? and left(kqdate,7)=? and kqdate<='" + rq + "'";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取当月产假天数
     */
    private static String getdycjts(String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        String sql = "select count(a.resourceid) from kq_format_total a " +
                " join kq_flow_split_leave b on a.resourceid=b.resourceid and a.kqdate=b.fromdate and a.kqdate=b.todate " +
                " where b.newleavetype=8 and ifnull(a.workdays,'') !='' and ifnull(a.attendancedays,0)=0 " +
                " and ifnull(a.leaveMins,0)>0 and a.resourceid=? and left(kqdate,7)=?";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }


    /**
     * 获取工作扣款比例
     */
    private static String getKkbl(String resourceid, String yearMonth, String bjts) {
        // RecordSet rs = new RecordSet();
        rs.executeQuery("select workyear,companyworkyear from hrmresource where id=?", resourceid);
        rs.next();
        String gl = Util.null2String(rs.getString("workyear"));
        String sl = Util.null2String(rs.getString("companyworkyear"));
        baseBean.writeLog(">>>>getKkbl>>>gl=" + gl + ",sl=" + sl);
        rs.executeQuery("select jszq from uf_jszq where (glqs<'" + gl + "' and '" + gl + "'<=gljs) " +
                "and (slqs<'" + sl + "' and '" + sl + "'<=sljs)");
        rs.next();
        int jszq = Util.getIntValue(rs.getString("jszq"));
        String begdate = getBeginDate(yearMonth, jszq);
        String enddate = getEndDate(yearMonth);
        baseBean.writeLog(">>>>getKkbl>>>begdate=" + begdate + ",enddate =" + enddate);
        String sql = "select sum(ifnull(duration,0)) from kq_flow_split_leave where resourceid=? and fromdate>='" + begdate + "' and todate<='" + enddate + "'";
        rs.executeQuery(sql, resourceid);
        rs.next();
        String duration = Util.null2String(rs.getString(1));
        String bjzqts = fAdd(duration, bjts);
        String ylq = fDivide(bjzqts, "30");
        baseBean.writeLog(">>>>getKkbl>>>bjzqts=" + bjzqts + ",ylq =" + ylq);
        String sql1 = "select gzkkbl from uf_gzkkbl where (glqs<='" + gl + "' and '" + gl + "'<=gljs)";
        if (fCompare(ylq, "6") <= 0) {
            sql1 += " and ylqqs=0";
        } else {
            sql1 += " and ylqqs=6";
        }
        rs.executeQuery(sql1);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    private static String getBeginDate(String yearMonth, int val) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DateUtil.parseToDate(yearMonth + "-01"));
        calendar = DateUtil.addMonth(calendar, val);
        return DateUtil.getDate(calendar.getTime());
    }

    private static String getEndDate(String yearMonth) {
        Calendar calendar = Calendar.getInstance();
        String lastdate = DateUtil.getLastDayOfMonth(yearMonth + "-01");
        calendar.setTime(DateUtil.parseToDate(lastdate));
        calendar = DateUtil.addMonth(calendar, -1);
        return DateUtil.getDate(calendar.getTime());
    }

    /**
     * 获取考勤报表中的矿工天数
     */
    private static String getKqKgts(String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        String sql = "select sum(absenteeism) from kq_format_total where resourceid=? and left(kqdate,7)=?";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取考勤报表中的事假天数
     */
    private static String getKqSjts(String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        String sql = "select count(a.resourceid) from kq_format_total a " +
                "join kq_flow_split_leave b on a.resourceid=b.resourceid and a.kqdate=b.fromdate and a.kqdate=b.todate " +
                "where b.newleavetype=6 and ifnull(a.workdays,'') !='' and ifnull(a.attendancedays,0)=0 " +
                "and ifnull(a.leaveMins,0)>0 and a.resourceid=? and left(kqdate,7)=? ";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取考勤报表中的病假天数
     */
    private static String getKqBjts(String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        String sql = "select count(a.resourceid) from kq_format_total a " +
                "join kq_flow_split_leave b on a.resourceid=b.resourceid and a.kqdate=b.fromdate and a.kqdate=b.todate " +
                "where b.newleavetype=7 and ifnull(a.workdays,'') !='' and ifnull(a.attendancedays,0)=0 " +
                "and ifnull(a.leaveMins,0)>0 and a.resourceid=? and left(kqdate,7)=?";
        rs.executeQuery(sql, resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取实际应出勤天数
     */
    private static String getSjYcqts(String resourceid, String yearMonth) {
        //RecordSet rs = new RecordSet();
        rs.executeQuery("select sum(workdays) from kq_format_total where resourceid=?" +
                " and substr(kqdate,1,7)=? and workdays=1", resourceid, yearMonth);
        rs.next();
        return Util.null2String(rs.getString(1));
    }

    /**
     * 获取考勤节假日天数
     */
    private static JSONObject getKqJjrts(String yearMonth, String rzrq, String lzrq, String zzrq) {
        JSONObject resultJson = new JSONObject();
        if (!"".equals(zzrq)) {
            String sql1 = "select count(id) from KQ_HolidaySet where groupid=4 and changetype=1 " +
                    "and left(holidaydate,7)=? ";
            if (!"".equals(rzrq)) {
                sql1 += " and holidaydate>='" + rzrq + "' and holidaydate<'" + zzrq + "' ";
            } else {
                sql1 += " and holidaydate<'" + zzrq + "' ";
            }
            rs.executeQuery(sql1, yearMonth);
            rs.next();
            String syqjjrts = Util.null2String(rs.getString(1));
            resultJson.put("syqjjrts", syqjjrts);
            String sql2 = "select count(id) from KQ_HolidaySet where groupid=4 and changetype=1 " +
                    "and left(holidaydate,7)=? ";
            if (!"".equals(lzrq)) {
                sql2 += "and holidaydate>='" + zzrq + "' and holidaydate<='" + lzrq + "' ";
            } else {
                sql2 += " and holidaydate>='" + zzrq + "' ";
            }
            rs.executeQuery(sql2, yearMonth);
            rs.next();
            String zsjjrts = Util.null2String(rs.getString(1));
            resultJson.put("zsjjrts", zsjjrts);
        } else {
            String sql = "select count(id) from KQ_HolidaySet where groupid=4 and changetype=1 " +
                    "and left(holidaydate,7)=? ";
            if (!"".equals(rzrq)) {
                sql += " and holidaydate>='" + rzrq + "' ";
            }
            if (!"".equals(lzrq)) {
                sql += " and holidaydate<='" + lzrq + "' ";
            }
            rs.executeQuery(sql, yearMonth);
            rs.next();
            resultJson.put("syqjjrts", Util.null2String(rs.getString(1)));
            resultJson.put("zsjjrts", "0");
        }

        return resultJson;
    }

    /**
     * 获取行项目是否锁定
     */
    private static JSONObject getLockColumns(String id) {
        //RecordSet rs = new RecordSet();
        JSONObject dataJson = new JSONObject();
        rs.executeQuery("select lock_salary_item_ids from hrsa_salary_acct_record where id=?", id);
        rs.next();
        String salaryItem = Util.null2String(rs.getString(1));
        if (salaryItem.contains("1685372097244")) {
            dataJson.put("dbbt", "LOCK");
        } else {
            dataJson.put("dbbt", "UNLOCK");
        }
        if (salaryItem.contains("1685457697632")) {
            dataJson.put("mxbt", "LOCK");
        } else {
            dataJson.put("mxbt", "UNLOCK");
        }
        if (salaryItem.contains("1685393314306")) {
            dataJson.put("bzgzhj", "LOCK");
        } else {
            dataJson.put("bzgzhj", "UNLOCK");
        }
        if (salaryItem.contains("1686028676893")) {
            dataJson.put("kgkk", "LOCK");
        } else {
            dataJson.put("kgkk", "UNLOCK");
        }
        if (salaryItem.contains("1686034175111")) {
            dataJson.put("sjkc", "LOCK");
        } else {
            dataJson.put("sjkc", "UNLOCK");
        }
        if (salaryItem.contains("1686034165433")) {
            dataJson.put("bjkc", "LOCK");
        } else {
            dataJson.put("bjkc", "UNLOCK");
        }
        if (salaryItem.contains("1686034194909")) {
            dataJson.put("cjgzkk", "LOCK");
        } else {
            dataJson.put("cjgzkk", "UNLOCK");
        }
        if (salaryItem.contains("1685393062388")) {
            dataJson.put("kqkxhj", "LOCK");
        } else {
            dataJson.put("kqkxhj", "UNLOCK");
        }
        return dataJson;
    }

    // f点型相加
    private static String fAdd(String a, String b) {
        a = isZero(a);
        b = isZero(b);
        BigDecimal bg1 = new BigDecimal(a);
        BigDecimal bg2 = new BigDecimal(b);
        BigDecimal bd = bg1.add(bg2);
        return bd.toString();
    }

    // f点型相减
    private static String fSubtract(String a, String b) {
        a = isZero(a);
        b = isZero(b);
        BigDecimal bg1 = new BigDecimal(a);
        BigDecimal bg2 = new BigDecimal(b);
        BigDecimal bd = bg1.subtract(bg2);
        return bd.toString();
    }

    // 除法保留2位小数 四舍五入
    private static String fDivide(String a, String b) {
        a = isZero(a);
        b = isZero(b);
        BigDecimal bg1 = new BigDecimal(a);
        BigDecimal bg2 = new BigDecimal(b);
        BigDecimal bd = bg1.divide(bg2, 2, BigDecimal.ROUND_HALF_UP);
        return bd.toString();
    }
    /**
     *
     * @Title: fDivide
     * @Description: 除法保留小数位
     * @param @param a
     * @param @param b
     * @param @param n 几位小数
     * @param @return 设定文件
     * @return String 返回类型
     * @throws
     */
    public static String fDivide(String a, String b, int n) {
        a = isZero(a);
        b = isZero(b);
        BigDecimal bg1 = new BigDecimal(a);
        BigDecimal bg2 = new BigDecimal(b);
        BigDecimal bd = bg1.divide(bg2, n, BigDecimal.ROUND_HALF_UP);
        return bd.toString();
    }
    // 乘法保留小数位 四舍五入
    private static String fMultiply(String a, String b) {
        a = isZero(a);
        b = isZero(b);
        BigDecimal bg1 = new BigDecimal(a);
        BigDecimal bg2 = new BigDecimal(b);
        BigDecimal bd = bg1.multiply(bg2).setScale(2, BigDecimal.ROUND_HALF_UP);
        return bd.toString();
    }
    // 乘法保留小数位 四舍五入
    private static String fMultiply(String a, String b,int n) {
        a = isZero(a);
        b = isZero(b);
        BigDecimal bg1 = new BigDecimal(a);
        BigDecimal bg2 = new BigDecimal(b);
        BigDecimal bd = bg1.multiply(bg2).setScale(n, BigDecimal.ROUND_HALF_UP);
        return bd.toString();
    }
    // 大小比较 -1 0 1
    private static int fCompare(String a, String b) {
        a = isZero(a);
        b = isZero(b);
        BigDecimal bg1 = new BigDecimal(a);
        BigDecimal bg2 = new BigDecimal(b);
        return bg1.compareTo(bg2);
    }

    // 取绝对值
    private static String fabs(String a) {
        a = isZero(a);
        BigDecimal bg1 = new BigDecimal(a);
        return bg1.abs().toString();
    }

    //零判断
    private static String isZero(String a) {
        if ("".equals(a)) {
            a = "0";
        }
        return a;
    }

    //比较年月的大小
    private static int compareToYearMonth(String yearMonth1, String yearMonth2) {
        int result = 0;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
            Date date1 = sdf.parse(yearMonth1);
            Date date2 = sdf.parse(yearMonth2);
            result = date1.compareTo(date2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
%>